home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS05.ADF / IFF / gio.h < prev    next >
C/C++ Source or Header  |  1986-04-20  |  6KB  |  154 lines

  1.  
  2. #ifndef GIO_H
  3. #define GIO_H
  4. /*----------------------------------------------------------------------*/
  5. /* GIO.H  defs for Generic I/O Speed Up Package.               1/23/86 */
  6. /* See GIOCall.C for an example of usage.                   */
  7. /* Read not speeded-up yet.  Only one Write file buffered at a time.  */
  8. /*                                           */
  9. /* Note: The speed-up provided is ONLY significant for code such as IFF */
  10. /* which does numerous small Writes and Seeks.                   */
  11. /*                                           */
  12. /* WARNING: If gio reports an error to you and you care what specific */
  13. /* Dos error was, you must call IoErr() BEFORE calling any other gio  */
  14. /* functions.                                     */
  15. /*                                                                      */ 
  16. /* By Jerry Morrison and Steve Shaw, Electronic Arts.                   */ 
  17. /* This software is in the public domain.                               */ 
  18. /*                                                                      */ 
  19. /* This version for the Commodore-Amiga computer.                       */
  20. /*                                                                      */ 
  21. /*----------------------------------------------------------------------*/
  22.  
  23. /* Use this file interface in place of ALL Open,Close,Read,Write,Seek DOS
  24.  * calls for an optional i/o speed-up via buffering.  You must use ONLY
  25.  * these G routines for a file that is being buffered; e.g., call GClose
  26.  * to Close the file, etc.
  27.  * It is harmless though not necessary to use G routines for a file that
  28.  * is not being buffered; e.g., GClose and Close are equivalent in that
  29.  * case.
  30.  * This Version only buffers one file at a time, and only for writing.
  31.  * If you call GWriteDeclare for a second file before the first file
  32.  * is GClosed, the first file becomes unbuffered.  This is harmless, no
  33.  * data is lost, the first file is simply no longer speeded-up.
  34.  */
  35.  
  36. /* Before compiling any modules that make G calls, or compiling gio.c,
  37.  * you must set the GIO_ACTIVE flag below.
  38.  *
  39.  * To omit the speed-up code,
  40.  *    #define GIO_ACTIVE 0
  41.  *
  42.  * To make the speed-up happen:
  43.  * 1. #define GIO_ACTIVE 1
  44.  * 2. link gio.o into your progrm
  45.  * 3. GWriteDeclare(file, buffer, size)
  46.  *    after GOpening the file and before doing
  47.  *    any writing.
  48.  * 4. ONLY use GRead, GWrite, GSeek, GClose -- do not use the DOS i/o
  49.  *    routines directly.
  50.  * 5. When done, do GClose.  Or to stop buffering without closing the
  51.  *    file, do GWriteUndeclare(file).
  52.  */
  53. #define GIO_ACTIVE 0
  54.  
  55. #ifndef COMPILER_H
  56. #include "iff/compiler.h"
  57. #endif
  58.  
  59. #ifndef LIBRARIES_DOS_H
  60. #include "libraries/dos.h"
  61. #endif
  62.  
  63. #ifndef OFFSET_BEGINNING
  64. #define OFFSET_BEGINNING OFFSET_BEGINING
  65. #endif
  66.  
  67. #if GIO_ACTIVE
  68.  
  69. #ifdef FDwAT  /* Compiler handles Function Declaration with Argument Types */
  70.  
  71. /* Present for completeness in the interface.
  72.  * "openmode" is either MODE_OLDFILE to read/write an existing file, or
  73.  * MODE_NEWFILE to write a new file.
  74.  * RETURNs a "file" pointer to a system-supplied structure that describes
  75.  * the open file.  This pointer is passed in to the other routines below.*/
  76. extern BPTR GOpen(char * /*filename*/, LONG /*openmode*/);
  77.  
  78. /* NOTE: Flushes & Frees the write buffer.
  79.  * Returns -1 on error from Write.*/
  80. extern LONG GClose(BPTR /*file*/);
  81.  
  82. /* Read not speeded-up yet.
  83.  * GOpen the file, then do GReads to get successive chunks of data in
  84.  * the file.  Assumes the system can handle any number of bytes in each
  85.  * call, regardless of any block-structure of the device being read from.
  86.  * When done, GClose to free any system resources associated with an
  87.  * open file.*/
  88. extern LONG GRead(BPTR /*file*/, BYTE * /*buffer*/, LONG /*nBytes*/);
  89.  
  90. /* Writes out any data in write buffer for file.
  91.  * NOTE WHEN have Seeked into middle of buffer:
  92.  * GWriteFlush causes current position to be the end of the data written.
  93.  * -1 on error from Write.*/
  94. extern LONG GWriteFlush(BPTR /*file*/);
  95.  
  96. /* Sets up variables to describe a write buffer for the file.*/
  97. /* If the buffer already has data in it from an outstanding GWriteDeclare,
  98.  * then that buffer must first be flushed.
  99.  * RETURN -1 on error from Write for that previous buffer flush.
  100.  * See also "GWriteUndeclare".*/
  101. extern LONG GWriteDeclare(BPTR /*file*/, BYTE * /*buffer*/, LONG /*nBytes*/);
  102.  
  103. /* ANY PROGRAM WHICH USES "GWrite" MUST USE "GSeek" rather than "Seek"
  104.  * TO SEEK ON A FILE BEING WRITTEN WITH "GWrite".
  105.  * "Write" with Generic speed-up.
  106.  * -1 on error from Write.  else returns # bytes written to disk.
  107.  * Call GOpen, then do successive GWrites with GSeeks if required,
  108.  * then GClose when done.  (IFF does require GSeek.)*/
  109. extern LONG GWrite(BPTR /*file*/, BYTE * /*buffer*/, LONG /*nBytes*/);
  110.  
  111. /* "Seek" with Generic speed-up, for a file being written with GWrite.*/
  112. /* Returns what Seek returns, which appears to be the position BEFORE
  113.  * seeking, though the documentation says it returns the NEW position.
  114.  * In fact, the code now explicitly returns the OLD position when
  115.  * seeking within the buffer.
  116.  * Eventually, will support two independent files, one being read, the
  117.  * other being written.  Or could support even more.  Designed so is safe
  118.  * to call even for files which aren't being buffered.*/
  119. extern LONG GSeek(BPTR /*file*/, LONG /*position*/, LONG /*mode*/);
  120.  
  121. #else /*not FDwAT*/
  122.  
  123. extern BPTR GOpen();
  124. extern LONG GClose();
  125. extern LONG GRead();
  126. extern LONG GWriteFlush();
  127. extern LONG GWriteDeclare();
  128. extern LONG GWrite();
  129. extern LONG GSeek();
  130.  
  131. #endif FDwAT
  132.  
  133. #else /* not GIO_ACTIVE */
  134.  
  135. #define GOpen(filename, openmode)           Open(filename, openmode)
  136. #define GClose(file)                   Close(file)
  137. #define GRead(file, buffer, nBytes)         Read(file, buffer, nBytes)
  138. #define GWriteFlush(file)              (0)
  139. #define GWriteDeclare(file, buffer, nBytes) (0)
  140. #define GWrite(file, buffer, nBytes)        Write(file, buffer, nBytes)
  141. #define GSeek(file, position, mode)         Seek(file, position, mode)
  142.  
  143. #endif GIO_ACTIVE
  144.  
  145.  
  146. /* Release the buffer for that file, flushing it to disk if it has any
  147.  * contents.  GWriteUndeclare(NULL) to release ALL buffers.
  148.  * Currently, only one file can be buffered at a time anyway.*/
  149. #define GWriteUndeclare(file)  GWriteDeclare(file, NULL, 0)
  150.  
  151.  
  152. #endif
  153.  
  154.